<html>
<head>
    <meta charset="utf-8">
    <title>Parsleyjs Mocha Tests</title>
    <link rel="stylesheet" href="mocha.css" />
    <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-XXXXXXXXX-X']);
      _gaq.push(['_trackPageview']);

      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();

    </script>
    <script type="text/javascript">
        function pause ( ms ) {
            ms += new Date().getTime();
            while ( new Date() < ms ){}
        }

        function jsAppend ( js_file, fn ) {
          if ( 'string' === typeof js_file ) {
              js_file = [ js_file ];
          }

          for ( var i in js_file ) {
              var js_script = document.createElement( 'script' );
              js_script.type = "text/javascript";
              js_script.src = js_file[ i ];
              document.getElementsByTagName( 'head' )[ 0 ].appendChild( js_script );
          }

          return 'function' == typeof fn ? fn() : true;
        }
    </script>
</head>
<body>
    <div id="info"></div>
    <div id="mocha"></div>

    <div style="display: none;">
        <form data-validate="parsley">
            <input type="text" id="input1" data-minlength="6" data-trigger="change keyup" />
            <input type="hidden" id="hidden" />
            <textarea id="textarea1"></textarea>
        </form>
        <form>
            <input type="text" id="input2" data-validate="parsley" data-type="email" />
            <textarea id="textarea2"></textarea>
        </form>
        <form data-validate="parsley">
            <input type="text" id="errormanagement" data-minlength="6" data-maxlength="10" data-type="alphanum" />
            <input type="text" id="errorMessage" data-error-message="This is my <strong>custom</strong> message" data-minlength="20" data-type="email" />
        </form>
        <form id="validator-tests" data-validate="parsley">
            <input type="text" id="notnull" data-notnull="true" />
            <input type="text" id="notblank" data-notblank="true" />

            <input type="text" id="required" data-required="true" />
            <input type="text" id="required-class" class="required" />
            <input type="text" id="required-html5" required="required" />
            <input type="text" id="required-html5-bis" required />
            <select id="required-selectmultiple" multiple="multiple" name="selectmultiple" data-required="true">
                <option value="">Select</option>
                <option value="foo">foo</option>
                <option value="bar">bar</option>
            </select>

            <input type="text" id="minlength" data-minlength="6" />
            <input type="text" id="maxlength" data-maxlength="6" />
            <input type="text" id="rangelength" data-rangelength="[6,10]" />
            <input type="text" id="min" data-min="10" />
            <input type="text" id="max" data-max="10" />
            <input type="number" id="min-html5" min="10" />
            <input type="number" id="max-html5" max="10" />

            <input type="text" id="range" data-range="[6,10]" />

            <input type="text" id="regexp" data-regexp="\d+" />
            <input type="text" id="regexp-html5" pattern="\d+" />
            <input type="text" id="regexp-flag1" data-regexp="^[A-Z]" />
            <input type="text" id="regexp-flag2" data-regexp="^[A-Z]" data-regexp-flag="i" />

            <input type="text" id="typeemail" data-type="email" />
            <input type="email" id="typeemail-html5" />

            <input type="range" id="typerange-html5" min="5" max="10" />

            <input type="text" id="typeurl" data-type="url" />
            <input type="url" id="typeurl-html5" />

            <input type="text" id="typeurlstrict" data-type="urlstrict" />
            <input type="text" id="typedigits" data-type="digits" />
            <input type="text" id="typenumber" data-type="number" />
            <input type="text" id="typedateIso" data-type="dateIso" />
            <input type="text" id="typealphanum" data-type="alphanum" />
            <input type="text" id="typephone" data-type="phone" />

            <input type="text" id="customvalidator" data-multiple="9" />

            <input type="text" id="equalTo-model" value="foobar" />
            <input type="text" id="equalTo" data-equalTo="#equalTo-model" />

            <input type="checkbox" id="checkbox-mincheck1" name="mincheck[]" value="foo" data-mincheck="2" />
            <input type="checkbox" id="checkbox-mincheck2" name="mincheck[]" value="bar" />

            <input type="checkbox" id="checkbox-mincheckgroup1" value="foo" data-group="foo" data-mincheck="2" />
            <input type="checkbox" id="checkbox-mincheckgroup2" value="bar" data-group="foo" />

            <input type="checkbox" id="checkbox-maxcheck1" name="maxcheck[]" value="foo" data-maxcheck="2" data-trigger="change"/>
            <input type="checkbox" id="checkbox-maxcheck2" name="maxcheck[]" value="bar" />
            <input type="checkbox" id="checkbox-maxcheck3" name="maxcheck[]" value="baz" />

            <input type="checkbox" id="checkbox-rangecheck1" name="rangecheck[]" value="foo" data-rangecheck="[2,3]" />
            <input type="checkbox" id="checkbox-rangecheck2" name="rangecheck[]" value="bar" />
            <input type="checkbox" id="checkbox-rangecheck3" name="rangecheck[]" value="baz" />
            <input type="checkbox" id="checkbox-rangecheck4" name="rangecheck[]" value="boz" />

            <input type="checkbox" id="checkbox-maxcheckchange1" name="maxcheckchange[]" value="foo" data-maxcheck="2" />
            <input type="checkbox" id="checkbox-maxcheckchange2" name="maxcheckchange[]" value="bar" />
            <input type="checkbox" id="checkbox-maxcheckchange3" name="maxcheckchange[]" value="baz" />

            <input type="text" id="remote1" name="remote1" data-remote="http://foo.bar" data-remote-datatype="jsonp" />
            <input type="text" id="remote2" name="remote2" data-remote="http://foo.bar/baz" data-trigger="change" data-remote-method="POST" />

            <input type="text" id="datavalue1" name="datavalue1" data-value="" value="" data-required="true" />
            <input type="text" id="datavalue2" name="datavalue2" data-value="foo" value="" data-required="true" />

            <input type="submit" />
        </form>
        <form id="validate-form" data-validate="parsley">
            <input type="text" id="validate1" data-required="true" />
            <input type="text" id="validate2" data-minlength="6" />
            <input type="submit" id="validate-form-submit" />
        </form>
        <form id="change-validation" data-validate="parsley">
            <input type="text" id="minchar-change" data-type="email" data-trigger="keyup" data-validation-minlength="7" />
        </form>
        <form id="change-show-errors" data-show-errors="false">
            <input type="text" id="change-show-errors-field1" data-type="email" data-trigger="keyup" data-validation-minlength="0" />
            <input type="text" id="change-show-errors-field2" data-type="url" />
        </form>
        <form id="requiredchanged1-form">
            <input type="text" id="requiredchanged1" data-required="true" />
        </form>
        <form id="requiredchanged2-form">
            <input type="text" id="requiredchanged2" data-required="true" />
            <input type="text" id="requiredchanged3" data-required="true" data-type="email" data-required-message="custom required" data-type-email-message="custom email" />
        </form>

        <form id="errorsmanagement-form">
            <label id="errorsmanagement-labelinfo"></label>
            <label id="errorsmanagement-labelerror"></label>
            <input type="text" id="errorsmanagement-email" data-type="email" />
        </form>

        <form id="validation-scenarios" data-validate="parsley">
            <input type="text" id="scenario-multiple-errors-and-required" data-required="true" data-type="email" data-rangelength="[20,50]" >
            <input type="text" id="scenario-not-required" data-trigger="keyup" data-minlength="6" />
            <input type="text" id="scenario-keyup-when-notvalid" data-trigger="change" data-type="email" />
            <input type="text" id="scenario-validation-after-field-reset" data-trigger="keyup" data-required="true" />
            <select id="scenario-validation-change-select" data-required="true">
                <option value="">Chose</option>
                <option value="foo">foo</option>
                <option value="bar">bar</option>
            </select>
        </form>
        <form data-validate="parsley" id="focus-form" data-focus="last">
            <input type="text" id="focus1" data-type="email" data-required="true" />
            <input type="text" id="focus2" data-type="email" data-required="true" />
        </form>
        <form data-validate="parsley" id="focus-form2" data-focus="none">
            <input type="text" id="focus3" data-type="email" data-required="true" />
            <input type="text" id="focus4" data-type="email" data-required="true" />
        </form>
        <form data-validate="parsley" id="hidden-input-form">
            <input type="text" id="hidden-input1" data-type="email" data-required="true" />
            <input type="hidden" id="hidden-input2" />
        </form>
        <form data-validate="parsley" id="destroy">
            <input type="text" data-type="email" id="destroy-email" data-trigger="change" />
            <input type="select" id="destroy-multiple" data-required="true"></input>
        </form>
        <form data-validate="parsley" id="reset">
            <input type="text" id="reset-email" data-required="true" />
            <textarea id="reset-textarea" data-required="true"></textarea>
        </form>
        <form data-validate="parsley" id="dynamic-form" data-triggers="keyup change">
        </form>
        <form data-validate="parsley" id="onthefly-form">
            <input type="text" id="onthefly" />
        </form>
        <form dat-validate="parsley" id="dataerrorcontainer-form">
            <input id="dataerrorcontainer" type="text" required data-error-container="#mycustomerrorcontainer" />
        </form>
        <form dat-validate="parsley" id="isValid-form">
            <input id="isValid-field" type="text" required />
        </form>
        <div id="mycustomerrorcontainer"></div>
        <form data-validate="parsley" id="onFieldValidate-form">
            <input type="text" id="onFieldValidate1" data-type="email" data-required="true" />
            <input type="text" id="onFieldValidate2" data-type="email" data-required="true" />
        </form>
        <form id="alwaysValidate-form">
            <input type="text" id="alwaysValidate" data-type="email" />
        </form>
        <form data-validate="parsley" id="listeners-form">
            <input type="text" id="listeners1" data-type="email" data-required="true" />
        </form>
        <form data-validate="parsley" id="onFieldValidatetrue-form">
            <input type="text" id="onFieldValidatefalse" data-type="email" data-required="true" />
            <input type="text" id="onFieldValidatetrue" data-type="email" data-required="true" />
        </form>
        <form data-validate="parsley" id="addListenerFieldValidate">
            <input type="text" id="addListenerFieldValidate-field" data-type="email" data-required="true" />
        </form>
        <form id="onFormValidateCustom">
            <input type="text" id="onFormValidateCustom-field" data-type="email" data-required="true" />
        </form>
        <form data-validate="parsley" id="radiocheckboxes">
            <div id="radio-parent">
                <input type="radio" id="radio1" name="radio" value="radio1" />
                <input type="radio" id="radio2" name="radio" value="radio2" data-required="true" />
            </div>
            <div id="check_parent">
                <input type="checkbox" id="check1" name="check[]" value="check1" data-required="true" />
                <input type="checkbox" id="check2" name="check[]" value="check2" data-required="true" />
            </div>
        </form>

        <form data-validate="parsley">
            <input type="text" id="minwords" data-minwords="6" />
            <input type="text" id="maxwords" data-maxwords="6" />
            <input type="text" id="rangewords" data-rangewords="[6, 10]" />
            <input type="text" id="greaterThan-model" value="1" />
            <input type="text" id="greaterThan" data-greaterthan="#greaterThan-model" />
            <input type="text" id="lessThan-model" value="2" />
            <input type="text" id="lessThan" data-lessthan="#lessThan-model" />
            <input type="text" id="beforeDate-model" value="1/1/2014" />
            <input type="text" id="beforeDate" data-beforedate="#beforeDate-model" />
            <input type="text" id="afterDate-model" value="1/1/2014" />
            <input type="text" id="afterDate" data-afterdate="#afterDate-model" />
            <input type="text" id="inList" data-inlist="true, 1, valid, value with spaces, yes, one" />
            <input type="text" id="inListSingleValue" data-inlist="true" />
            <input type="text" id="inListEmpty" data-inlist="" />
            <input type="text" id="inListSingleComma" data-inlist="," />
            <input type="text" id="inListCustomDelimiter" data-inlist="foo | bar | foo bar" data-inlist-delimiter="|" />

            <input type="text" id="luhn" data-luhn="true" />
            <input type="text" id="americanDate" data-americandate="true" />
            <input type="text" id="es_dni" data-es_dni="true" />
            <input type="text" id="es_cif" data-es_cif="true" />
            <input type="text" id="es_postalcode" data-es_postalcode="true" />
            <input type="text" id="es_ssn" data-es_ssn="true" />
            <input type="text" id="es_ccc" data-es_ccc="true" />
        </form>

        <div data-validate="parsley" data-bind="true">
            <input type="text" id="bindNonFormInput" data-required="true" value="" />
        </div>
    </div>

    <script type="text/javascript">
        var jquery = 'resources/jquery.min.js'
          , zepto = 'resources/zepto-1.0rc1[zepto.event.data.ajax.fx.fx_modules].js';

        switch ( location.hash ) {
            case '#jquery':
                jsAppend( jquery , pause( 100 ) );
                jsAppend( '../parsley.js' , pause( 50 ) );
                jsAppend( '../parsley.extend.js' , pause( 50 ) );
                jsAppend( '../l10n/parsley.es.js' , pause( 50 ) );
                document.getElementById( 'info' ).innerHTML = 'Parsley test suite for jQuery, unminified version';
                break;
            case '#zepto':
                jsAppend( zepto , pause( 100 ) );
                jsAppend( '../parsley.js' , pause( 50 ) );
                jsAppend( '../parsley.extend.js' , pause( 50 ) );
                jsAppend( '../l10n/parsley.es.js' , pause( 50 ) );
                document.getElementById( 'info' ).innerHTML = 'Parsley test suite for Zepto, unminified version';
                break;
            case '#zepto-min':
                jsAppend( zepto , pause( 100 ) );
                jsAppend( '../dist/parsley.min.js' , pause( 50 ) );
                jsAppend( '../dist/parsley.extend.min.js' , pause( 50 ) );
                jsAppend( '../dist/parsley.es.min.js' , pause( 50 ) );
                document.getElementById( 'info' ).innerHTML = 'Parsley test suite for Zepto, minified version';
                break;
            case '#jquery-min':
                jsAppend( jquery , pause( 100 ) );
                jsAppend( '../dist/parsley.min.js' , pause( 50 ) );
                jsAppend( '../dist/parsley.extend.min.js' , pause( 50 ) );
                jsAppend( '../dist/parsley.es.min.js' , pause( 50 ) );
                document.getElementById( 'info' ).innerHTML = 'Parsley test suite for jQuery, minified version';
                break;
            case '#standalone':
            default:
                jsAppend( '../dist/parsley-standalone.min.js' , pause( 100 ) );
                jsAppend( '../dist/parsley.extend.min.js' , pause( 50 ) );
                jsAppend( '../dist/parsley.es.min.js' , pause( 50 ) );
                document.getElementById( 'info' ).innerHTML = 'Parsley test suite - Standalone Zepto Minified version';
                break;
        }

        jsAppend( [ 'mocha.js', 'expect.js', 'sinon.js', 'tests.js' ] );

        window.onload = function() {

            mocha.setup( 'bdd' );
            mocha.reporter( 'html' );
            testSuite();

            if ( window.mochaPhantomJS ) {
                mochaPhantomJS.run();
            } else {
                mocha.run();
            }
        };
    </script>
</body>
</html>
